﻿using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using VisionCloud.Core.Model.Ms;
using VisionCloud.Domain.Repository.Interface.Ms;

namespace VisionCloud.Domain.Repository.Implement.Ms
{
    public class MsProjectStandardMeasureItemValueRepository : BaseRepository<MsProjectStandardMeasureItemValue>, IMsProjectStandardMeasureItemValueRepository
    {
        /// <summary>
        /// 根据阶段获取测量项偏差值
        /// </summary>
        /// <param name="projectStandardId">阶段UUID</param>
        /// <returns></returns>
        public async Task<List<MsProjectStandardMeasureItemValue>> GetList(Guid projectStandardId, Guid ProjectGuid)
        {
            return await (
                from h in Db.MsProjectStandardMeasureItemValues
                where h.ProjectStandardId == projectStandardId && h.ProjectGuid == ProjectGuid
                select h).AsNoTracking().ToListAsync().ConfigureAwait(false);
        }

        public async Task<List<MsProjectStandardMeasureItemValue>> GetTemplateList()
        {
            return await (
                from h in Db.MsProjectStandardMeasureItemValues
                where h.ProjectGuid == new Guid()
                select h).AsNoTracking().ToListAsync().ConfigureAwait(false);
        }

        public async Task<List<MsProjectStandardMeasureItemValue>> GetDataByProjects(Guid[] projectIds)
        {
            return await (
            from h in Db.MsProjectStandardMeasureItemValues
            where projectIds.Contains(h.ProjectGuid)
            select h).AsNoTracking().ToListAsync().ConfigureAwait(false);
        }

        /// <summary>
        /// 根据项目阶段Id过滤
        /// </summary>
        /// <param name="projectIds">项目Id</param>
        /// <param name="excludeStandard">过滤项目阶段Id</param>
        /// <returns></returns>
        public async Task<List<MsProjectStandardMeasureItemValue>> GetDataByProjectsWithStandardId(Guid[] projectIds, Guid excludeStandard)
        {
            return await (
            from h in Db.MsProjectStandardMeasureItemValues
            where projectIds.Contains(h.ProjectGuid) && (h.ProjectStandardId != excludeStandard || excludeStandard == Guid.Empty)
            select h).AsNoTracking().ToListAsync().ConfigureAwait(false);
        }
    }
}